package myJs.api

import myJs.myPkg.MyFetch
import shared.Pojo._
import upickle.default.{read, write}
import myJs.Implicits._
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import shared.tsPojo.TsPojo
import upickle.default._

/**
 * Created by yz on 7/5/2022
 */
object BrowseCirc {

  import TsPojo.browseCirc._

  val baseUrl = s"${Api.apiUrl}/gepLiver/browseCirc"

  def allByServer(dataStr: String) = {
    val url = s"${baseUrl}/allByServer"
    MyFetch.postRnText(url = s"${url}", data = dataStr, headers = Map("Content-Type" -> "application/json")).map { str =>
      str.toObj
    }
  }

  def allGeneSymbol = {
    val url = s"${baseUrl}/allGeneSymbol"
    MyFetch.getRnStr(url = s"${url}", headers = Map("Content-Type" -> "application/json")).map { str =>
      read[List[String]](str)
    }
  }

  def allChr = {
    val url = s"${baseUrl}/allChr"
    MyFetch.getRnStr(url = s"${url}", headers = Map("Content-Type" -> "application/json")).map { str =>
      read[List[String]](str)
    }
  }

  def search(request: CircSearch.Request) = {
    val url = s"${baseUrl}/search"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
      read[List[ujson.Obj]](str)
    }
  }

  def circId2GeneName(request: CircId2GeneName.Request) = {
    val url = s"${baseUrl}/circId2GeneName"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
      read[String](str)
    }
  }

  def hTissueBoxplotImage(request: HTissueBoxplotImage.Request) = {
    val url = s"${baseUrl}/hTissueBoxplotImage"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
      read[HTissueBoxplotImage.Response](str)
    }
  }

  def mTissueBoxplotImage(request: MTissueBoxplotImage.Request) = {
    val url = s"${baseUrl}/mTissueBoxplotImage"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
      read[MTissueBoxplotImage.Response](str)
    }
  }

}
